package com.fangque.kepp.framework.result;

import com.fangque.kepp.framework.enums.ResultEnum;

/**
 * json 返回的格式
 * @author liyk
 */
public class ResultBean {
    private Integer code;
    private String message;
    private Object data;

    private ResultBean() {
    }

    public static ResultBean build() {
        return new ResultBean();
    }

    public static ResultBean ok(String msg, Object data) {
        return new ResultBean(200, msg, data);
    }

    public static ResultBean ok(String msg) {
        return new ResultBean(200, msg, null);
    }

    public static ResultBean success(String msg, Object data) {
        return new ResultBean(200, msg, data);
    }

    public static ResultBean success(String msg) {
        return new ResultBean(200, msg, null);
    }

    public static ResultBean error(String msg, Object data) {
        return new ResultBean(500, msg, data);
    }

    public static ResultBean error(String msg) {
        return new ResultBean(500, msg, null);
    }

    public static ResultBean error(ResultEnum resultEnum) {
        ResultBean resultUtil = new ResultBean();
        resultUtil.setCode(resultEnum.getCode());
        resultUtil.setMessage(resultEnum.getMsg());
        return resultUtil;
    }

    private ResultBean(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {

        return code;
    }

    public ResultBean setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public ResultBean setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public ResultBean setData(Object data) {
        this.data = data;
        return this;
    }
}
